﻿using AutoMapper;
using MediatR;
using S.Archives.Domain.S.ArchivesDto;
using S.Archives.Infrstructre.InterFace;
using S.Archives.Read.Api.Application.Command;

namespace S.Archives.Read.Api.Application.CommandHandlers
{
    public class SelMaleEmaleSelCommandHandler : IRequestHandler<SelMaleEmaleSelCommand, List<EnumStringDto>>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private  readonly IMapper mapper;
        public SelMaleEmaleSelCommandHandler(ISheepFileRepository shepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = shepFileRepository;
            this.mapper = mapper;

        }
        /// <summary>
        /// 根据档案类型获取电子耳标下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<EnumStringDto>> Handle(SelMaleEmaleSelCommand request, CancellationToken cancellationToken)
        {
            var list = sheepFileRepository.GetAllAsync().Result;
            if (request.FileType > 0)
            {
                list=list.Where(x => x.FileType == request.FileType).ToList();
            }
            
            
          
            List<EnumStringDto> enumDto = new List<EnumStringDto>();
            enumDto=mapper.Map<List<EnumStringDto>>(list);
            return  enumDto;

        }
    }
}
